WPS Office.apk(点击下载) / CloudPrintWebView.java


package cn.wps.moffice.common.beans.print;

import android.content.Context;
import android.net.http.SslError;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import cn.wps.moffice.common.beans.MaterialProgressBarCycle;

public class CloudPrintWebView extends WebView {
    private MaterialProgressBarCycle dpa;
    private a dpb;
    private View.OnKeyListener dpc;

    public interface a {
        void aCG();
    }

    class b extends WebChromeClient {
        private b() {
        }

        /* synthetic */ b(CloudPrintWebView cloudPrintWebView, byte b) {
            this();
        }

        public final void onProgressChanged(WebView webView, int i) {
            if (CloudPrintWebView.this.dpa != null) {
                CloudPrintWebView.this.dpa.setVisibility(0);
            }
            if (i >= 100) {
                if (CloudPrintWebView.this.dpb != null) {
                    CloudPrintWebView.this.dpb.aCG();
                }
                webView.getSettings().setBlockNetworkImage(false);
                CloudPrintWebView.this.dpa.setVisibility(8);
                webView.setVisibility(0);
                webView.requestFocus();
            }
        }
    }

    class c extends WebViewClient {
        private c() {
        }

        /* synthetic */ c(CloudPrintWebView cloudPrintWebView, byte b) {
            this();
        }

        public final void onPageFinished(WebView webView, String str) {
            Log.d("page Url", str);
            if ("http://www.google.com/cloudprint/dialog.html".equalsIgnoreCase(str) || "https://www.google.com/cloudprint/dialog.html".equalsIgnoreCase(str)) {
                webView.loadUrl("javascript:printDialog.setPrintDocument(printDialog.createPrintDocument(window.PrintJSInterface.getType(),window.PrintJSInterface.getTitle(),window.PrintJSInterface.getContent(),window.PrintJSInterface.getEncoding()))");
                webView.loadUrl("javascript:window.addEventListener('message',function(evt){window.PrintJSInterface.onPostMessage(evt.data)}, false)");
            }
        }

        public final void onReceivedError(WebView webView, int i, String str, String str2) {
            if (i != -6 || !str2.equals("https://www.google.com/cloudprint/dialog.html")) {
                super.onReceivedError(webView, i, str, str2);
            } else {
                webView.loadUrl("http://www.google.com/cloudprint/dialog.html");
            }
        }

        public final void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            super.onReceivedSslError(webView, sslErrorHandler, sslError);
        }

        @Override // android.webkit.WebViewClient
        public final boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (!URLUtil.isNetworkUrl(str)) {
                return false;
            }
            webView.getSettings().setBlockNetworkImage(true);
            webView.loadUrl(str);
            return false;
        }
    }

    public CloudPrintWebView(Context context) {
        this(context, null);
    }

    public CloudPrintWebView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 16842885);
    }

    public CloudPrintWebView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        if (luf.gR(context)) {
            setBackgroundColor(-1);
        } else {
            setBackgroundColor(-2104085);
        }
        setHorizontalScrollBarEnabled(false);
        setScrollBarStyle(0);
        WebSettings settings = getSettings();
        settings.setSupportZoom(true);
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(true);
        settings.setBuiltInZoomControls(true);
        settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        if (Build.VERSION.SDK_INT >= 8) {
            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        }
        setWebViewClient(new c(this, (byte) 0));
        setWebChromeClient(new b(this, (byte) 0));
    }

    public boolean onKeyUp(int i, KeyEvent keyEvent) {
        return !super.onKeyUp(i, keyEvent) ? this.dpc.onKey(this, i, keyEvent) : true;
    }

    public void setJavaInterface(ddy ddy) {
        addJavascriptInterface(ddy, "PrintJSInterface");
    }

    public void setKeybackListener(View.OnKeyListener onKeyListener) {
        this.dpc = onKeyListener;
    }

    public void setOnLoadFinishedListener(a aVar) {
        this.dpb = aVar;
    }

    public void setProcessBar(MaterialProgressBarCycle materialProgressBarCycle) {
        this.dpa = materialProgressBarCycle;
    }
}